package com.zhangfei.sys.service.impl;


import com.zhang.entity.Examine;
import com.zhangfei.cilent.IUserClient;
import com.zhangfei.sys.dao.ExamineDao;
import com.zhangfei.sys.service.ExamineService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Examine)表服务实现类
 *
 * @author makejava
 * @since 2021-06-25 14:13:38
 */
@Service("examineService")
public class ExamineServiceImpl implements ExamineService {
    @Resource
    private ExamineDao examineDao;


    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 通过ID查询单条数据
     *
     * @param cid 主键
     * @return 实例对象
     */
    @Override
    public Examine queryById(Integer cid) {
        return this.examineDao.queryById(cid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Examine> queryAllByLimit(int offset, int limit) {
        return this.examineDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param examine 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Examine insert(Examine examine) {
        this.examineDao.insert(examine);
        rocketMQTemplate.syncSend("Nacos_Test",examine);
        return examine;
    }

    /**
     * 修改数据
     *
     * @param examine 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Examine update(Examine examine) {
        this.examineDao.update(examine);
        return this.queryById(examine.getCid());
    }

    /**
     * 通过主键删除数据
     *
     * @param cid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer cid) {
        return this.examineDao.deleteById(cid) > 0;
    }
}
